package com.yellowpage.wf.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;
import com.yellowpage.wf.dao.AttachmentDao;
import com.yellowpage.wf.data.Attachment;
import com.yellowpage.wf.data.WorkflowNode;

public class AttachmentServiceImpl extends BaseServiceImpl implements AttachmentService {
	  private AttachmentDao attachmentDao;
	
	  public void setAttachmentDao(AttachmentDao attachmentDao) {
		  this.attachmentDao = attachmentDao;
	  }
	
	
	  /* White generate Method */ 
	  public Attachment getAttachment(Long id) {
			return attachmentDao.get(id);
		}
	  public void saveAttachment(Attachment attachment)
	  {
		  attachmentDao.save(attachment);
	  }
	  public void updateAttachment(Attachment attachment)
	  {
		  attachmentDao.update(attachment);
	  }
	  public void delete(List deleteList){
		  attachmentDao.remove(deleteList);
	  }
	  public List<Map> getAttachmentOfWorkflow(Long workflowId){
		  
		  String sql = "select wa.attachment_id,wa.name,wa.type,wa.workflow_id,wa.resource_id,wa.description, " +
		  		" wa.create_user,wa.create_time, (select wre.name from wf_resource wre where wre.resource_id = wa.resource_id) as fname " +
		  		" from wf_attachment wa " +
		  		" where wa.workflow_id =" + workflowId.toString();
	
		  	QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(sql);
		  	List<Map> resultList = this.baseDao.query(sqlAssistant, new HashMap());
		  	return resultList;
	  }
}	